﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using PlanningGIS.Win.Controls;

namespace PlanningGIS.Statistics
{
    public partial class FrmVegStatPara :Office2007Form 
    {
        private Hashtable pHash;

        public FrmVegStatPara()
        {
            pHash = new Hashtable();
            InitializeComponent();
        }

        public Hashtable Parameters
        {
            get { return pHash; }
            set { pHash = value; }
        }

        private void FrmVegStatPara_Load(object sender, EventArgs e)
        {
            if (pHash == null || pHash.Count == 0)
            {
                return;
            }
            foreach (DictionaryEntry de in pHash)
            {
                string strName = de.Key.ToString();
                string strValue = de.Value.ToString();
                switch (strName)
                {
                    case "居民地面":
                        txtRes.Text = strValue;
                        break;
                    case "交通线":
                        txtTra.Text = strValue;
                        break;
                    default:
                        break;
                }
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (pHash == null)
            {
                pHash = new Hashtable();
            }
            else
            {
                pHash.Clear();
            }
           

            if (CheckInput(txtRes, "与居民地面距离"))
            {
                pHash.Add("居民地面", txtRes.Text.Trim());
            }
            else
            {
                return;
            }

            if (CheckInput(txtTra, "与道路结构线距离"))
            {
                pHash.Add("交通线", txtTra.Text.Trim());
            }
            else
            {
                return;
            }
            DialogResult = DialogResult.OK;
            Close();
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            pHash = null;
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private bool CheckInput(TextBox txt, string str)
        {
            if (txt.Text.Trim() == ".")
            {
                MsgHelper.ShowInfomationMsgbox(str + "不能为空！");
                return false;
            }
            double dblResult;
            if (!double.TryParse(txt.Text, out dblResult))
            {
                MsgHelper.ShowInfomationMsgbox(str + "输入不正确！");
                return false;
            }
            return true;
        }

        private void txtRes_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextBox_KeyPress(sender, e);
        }

        private void txtTra_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextBox_KeyPress(sender, e);
        }

        private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((int)e.KeyChar == 8)
            {
                e.Handled = false;
            }
            else if ((int)e.KeyChar == 12290 || (int)e.KeyChar == 12290)
            {
                e.KeyChar = (char)46;
                TextBox textbox = sender as TextBox;
                if (textbox.Text.Contains("."))
                {
                    e.Handled = true;
                }
                else
                {
                    e.Handled = false;
                }
            }
            else if ((int)e.KeyChar > 46 && (int)e.KeyChar < 58)
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }

        }

    }
}
